/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package es.tabla.activity;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

/**
 *
 * @author Chema
 */
public class CrearTabla extends Activity {

    /**
     * Called when the activity is first created.
     */
    LinearLayout ll;
    Button bSiguiente;
    Button bAtras;
    Button bFin;
    int i;

    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        try{
        incializar();
        }catch(Exception e)
        {

            mostrarErrores(e.toString());
        }
        // ToDo add your GUI initialization code here        
    }

    private void incializar() {

        i = 0;
        setContentView(R.layout.crear_tabla);
        ll = (LinearLayout) findViewById(R.id.ll1);
        bSiguiente = (Button) findViewById(R.id.bSiguiente);
        bAtras = (Button) findViewById(R.id.bAtras);
        //////////////quitar este boton y gestionarlo con bSiguiente
        bFin = (Button) findViewById(R.id.bFin);

        bSiguiente.setOnClickListener(new OnClickListener() {

            public void onClick(View arg0) {

                siguienteLL();
            }
        });

        bAtras.setOnClickListener(new OnClickListener() {

            public void onClick(View arg0) {

                anteriorLL();
            }
        });

         bFin.setOnClickListener(new OnClickListener() {

            public void onClick(View arg0) {

                anteriorLL();
            }
        });

        ((LinearLayout) findViewById(R.id.ll2)).setVisibility(View.INVISIBLE);
        ((LinearLayout) findViewById(R.id.ll3)).setVisibility(View.INVISIBLE);
        ((LinearLayout) findViewById(R.id.ll4)).setVisibility(View.INVISIBLE);
        ((LinearLayout) findViewById(R.id.ll5)).setVisibility(View.INVISIBLE);



    }

    void siguienteLL() {
        switch (i) {
            case 0:
                ll = (LinearLayout) findViewById(R.id.ll2);
                bAtras.setVisibility(View.VISIBLE);
                break;
            case 1:
                ll = (LinearLayout) findViewById(R.id.ll3);
                break;
            case 2:
                ll = (LinearLayout) findViewById(R.id.ll4);
                break;
            case 3:
                ll = (LinearLayout) findViewById(R.id.ll5);
                bSiguiente.setVisibility(View.GONE);
                bFin.setVisibility(View.VISIBLE);

                break;
        }

        if (i <= 5) {
            i++;
        }
    }

    void anteriorLL() {
        switch (i) {
            case 1:
                ll = (LinearLayout) findViewById(R.id.ll1);
                bAtras.setVisibility(View.GONE);
                break;
            case 2:
                ll = (LinearLayout) findViewById(R.id.ll2);
                break;
            case 3:
                ll = (LinearLayout) findViewById(R.id.ll3);
                break;
            case 4:
                ll = (LinearLayout) findViewById(R.id.ll4);
                bSiguiente.setVisibility(View.VISIBLE);
                bFin.setVisibility(View.INVISIBLE);
                break;
        }

        if (i > 0) {
            i--;
        }

    }


     private void mostrarErrores(String inicializar) {
        TextView tv = new TextView(this);
        tv.setText(inicializar);
        setContentView(tv);

    }
}
